<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/include/taglibs.jsp"%>

<SCRIPT LANGUAGE="JavaScript">
<!--
	function check_upload_fileext(fd){
		var exp = /(.jpg|.gif|.bmp|.png)$/
		if( fd.value == '' || fd.value.match(exp) ){
			return true;
		} else {
			alert('jpg. gif, bmp, png 파일만 업로드가 가능합니다.');
			return false;
		}
	}
//-->
</SCRIPT>

<script type="text/javascript">
<!--
function pboard_writeform_check(frm){
	if( board_writeform_check(frm) == true ) {
				get_Scode_write( frm.scode.value )
			}
	return false;
}
//-->
</script>
<script type="text/javascript">
function delFile(idx){
	$spanId = "#fileSpan_"+idx;
	$($spanId).remove();
}

function delExistFile(idx,fileIdx){
	if(confirm("삭제하겠습니까?")){
		$spanId = "#fileSpan_"+idx;
		$.getJSON(
			'/c_admin/img_delete.php',
			{
				id:fileIdx
			},
			function(data){
				if(data==null){
					alert("다시 시도해주세요.");
				}else{
					if(data==0){						
						$($spanId).remove();
						alert("삭제되었습니다.");
					}
				}
			}
		);
	}
}

$("#btnFileAdd").click(function(){
	var cnt = eval($("#fileCount").val())+1;
	if($("#fileDiv>span").length>=20){
		alert('20개까지만 추가가능 합니다.');
		return;
	}else{
		if($("#fileDiv>span").length==0){
			$("#fileDiv").append('<span id="fileSpan_'+cnt+'"><input class="css_input" type="file" id="file_'+cnt+'" name="file[]" title="파일" style="width:235px;"> <img src="/pboard/skin/default/img/btn_file_minus.gif" border="0" alt="" id="btnFileDel_'+cnt+'" onClick="javascript:delFile('+cnt+')" class="btnFileDel" atr="'+cnt+'" atType="insert"><br/> </span> '); 
		}else{
			$('<span id="fileSpan_'+cnt+'"><input class="css_input" type="file" id="file_'+cnt+'" name="file[]" title="파일" style="width:235px;"> <img src="/pboard/skin/default/img/btn_file_minus.gif" border="0" alt=""id="btnFileDel_'+cnt+'" onClick="javascript:delFile('+cnt+')" class="btnFileDel" atr="'+cnt+'" atType="insert"><br/> </span> ').insertAfter("#fileDiv>span:last-child"); 
		}
		$("#fileCount").val(cnt);
	}
});

$("#btnFileVal").click(function(){
	alert($("#fileDiv").html());
});

//데이터 저장
function saveData(){

	if(''==$("#bd_name").val()){
		alert("이름을 입력하세요");
		$("#bd_name").focus();
		return false;
	}
	if(''==$("#bd_pwd").val()){
		alert("비밀번호를 입력하세요. 삭제 또는 수정시 사용됩니다.");
		$("#bd_pwd").focus();
		return false;
	}
	if(''==$("#bd_title").val()){
		alert("제목을 입력하세요");
		$("#bd_title").focus();
		return false;
	}
	if(''==$("#bd_content").val()){
		alert("내용을 입력하세요");
		$("#bd_content").focus();
		return false;
	}
	
	$("#frmData").submit();
}

function addFile(){
	if($(".spanFile").length>19){
		alert("파일업로드는 20개까지만 가능합니다");
		return false;
	}

	var html = 
		"<span class=\"spanFile\">"+
		"<input style=\"width: 235px\" class=\"css_input\" title=\"파일\" name=\"file\" type=\"file\"> "+
		"<img style=\"cursor: hand\" class=\"btnfiledel\" onclick=\"deleteFile(this);\" border=\"0\" alt=\"파일삭제\" src=\"/usr/images/btn_file_minus.gif\" > "+
		"<br/>"+
		"</span>";
		
	if($(".spanFile").length==0){
		$("#fileDiv").html(html);
	}else{
		$(".spanFile:last").after(html);
	}

}

function deleteFile(me){
	$(me).parent().remove();
}
</script>



<table width="100%" border="0" cellspacing="0" cellpadding="0"
	align="center">
	<tr>
		<td valign="top" align="center">

			<TABLE width="100%" cellpadding="0" cellspacing="0">
				<TR>
					<TD><BR>
						<form action="./ubdmg0103T.do" name="frmData" id="frmData" method="post"
							ENCTYPE="multipart/form-data">
							<input type="hidden" name="p_id" value="${param.p_id }">
							<input type="hidden" name="brd_no" value="${param.brd_no }">
							<table cellspacing="0" cellpadding="0" border="0" width="100%">
								<tr>
									<td colspan="2" height="1" class="css_line"></td>
								</tr>
								<tr>
									<td width="100" class="sub1" align="center">&nbsp; 이름</td>
									<td class="sub3"><input type="text" name="bd_name" id="bd_name" value="<c:if test="${!empty sessionScope['userInfo'].admin_id || param.p_id == sessionScope['userInfo'].p_id }">${boardAttr.p_nm }</c:if>"
										class="css_input" style="width: 125px"></td>
								</tr>
								<tr <c:if test="${!empty sessionScope['userInfo'].admin_id || param.p_id == sessionScope['userInfo'].p_id }"> style="display: none;"</c:if>>
									<td width="100" class="sub1" align="center">&nbsp; 비밀번호</td>
									<td class="sub3"><input type="password" name="bd_pwd" id="bd_pwd"
										class="css_input" style="width: 125px" value="<c:if test="${!empty sessionScope['userInfo'].admin_id || param.p_id == sessionScope['userInfo'].p_id }">poiu;kjhsdfgwert!@</c:if>"></td>
								</tr>
								<tr>
									<td width="100" class="sub1" align="center">&nbsp; 이메일</td>
									<td class="sub3"><input type="text" name="bd_email" value=""
										class="css_input" style="width: 50%"></td>
								</tr>
								<tr>
									<td width="100" class="sub1" align="center">&nbsp; 제목</td>
									<td class="sub3"><input type="text" name="bd_title" id="bd_title"
										class="css_input" style="width: 95%"></td>
								</tr>
								<tr>
									<td colspan="2" height="1" class="css_line"></td>
								</tr>
								<tr valign="top">
									<td width="100" class="sub1" align="center">&nbsp; 내용</td>
									<td class="sub3"><TEXTAREA name="bd_content" id="bd_content" cols="65" rows="35"
											style="width: 95%; height: 200px;" class="css_input"></TEXTAREA>
									</td>
								</tr>
<c:if test="${'Y'==boardAttr.file_yn }">
								<tr>
									<td width="100" class="sub1" style="vertical-align: top;">&nbsp; 파일첨부 <a href="#" onclick="addFile();"><img src="/usr/images/btn_file_add.gif" style="vertical-align: middle; cursor: hand"/> </a> </td>
									<td class="sub3">
										<div id="fileDiv">
											<span class="spanFile">
											<input style="width: 235px" class="css_input" title="파일" name="file" type="file"> 
											<img style="cursor: hand" class="btnfiledel" onclick="deleteFile(this);" border="0" alt="파일삭제" src="/usr/images/btn_file_minus.gif" >
											<br/>
											</span>
										</div>
									</td>
								</tr>
</c:if>

								<tr>
									<td width="100" class="sub1" align="center">&nbsp; 잠금글</td>
									<td class="sub3"><label><INPUT TYPE="checkbox" name="secret_yn"
										value="Y"> 비공개 ( 비밀번호 일치해야 글보기 가능 )</label></td>
								</tr>
								<tr <c:if test="${!empty sessionScope['userInfo'].admin_id || param.p_id == sessionScope['userInfo'].p_id }"> style="display: none;"</c:if>>
									<td width="100" class="sub1" align="center">&nbsp; 입력코드</td>
									<td class="sub3"><input type="text" name="answer"
										class="css_input" style="width: 125px">
										<img id="chaImg" src="/captcha/simpleCaptcha.png" border=0 align=absmiddle style="height: 40px;"><a href="#" onclick="$('#chaImg').attr('src','/captcha/simpleCaptcha.png');return false;">[새로고침]</a>
									</td>
								</tr>
							</table>

							<!-- btn-->
							<div style="text-align: center; padding: 20px 5px 5px 0px">
								<a href="#" onclick="saveData();return false;"><img src="/usr/images/btn_conf.gif" border="0"></a>
								<a href="./ubdmg0101Q.do?p_id=${param.p_id }&brd_no=${param.brd_no }"><img
									src="/usr/images/btn_cancel.gif" border="0"></a>
							</div>
						</form></TD>
				</TR>
			</TABLE>
		</td>
	</tr>
</table>
